#!/bin/bash
# Copyright (c) 2024 maminjie <canpool@163.com>
# SPDX-License-Identifier: MulanPSL-2.0

CUR_DIR=$(dirname $(readlink -f "$0"))

map_file=$1
specs_dir=$2

if [[ $# -ne 2 || ! -f "$map_file" || ! -d "$specs_dir" ]]; then
    echo "usage: bash $0 map_file specs_dir"
    exit 0
fi

while read i; do
    repo=$(echo "$i" | cut -d , -f 1)
    spec_name=$(echo "$i" | cut -d , -f 2)
    if [[ -z "$spec_name" || "$spec_name" = "null" ]]; then
        continue
    fi
    if [ -f "$specs_dir/$spec_name" ]; then
        rm -f "$specs_dir/$spec_name"
    fi
    wget https://gitee.com/src-openeuler/$repo/raw/master/$spec_name.spec -N -P $specs_dir -o /dev/null
    if [ $? -eq 0 ]; then
        echo "$i success"
    else
        echo "$i failed"
    fi

done < $map_file
